const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const adminAuth = require('./middlewares/admin-auth')
const cors = require('cors');

require('dotenv').config();
const indexRouter = require('./routes/index');
const loginRouter = require('./routes/login');
const technicalRouter = require('./routes/technical_direction')
const registerRouter = require('./routes/register')
const categoryRouter = require('./routes/admin/category')
const authRouter = require('./routes/admin/auth')

const app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors());

app.use('/', indexRouter)
// app.use('/users', usersRouter);
app.use('/technical_direction',technicalRouter);
app.use('/api/login',loginRouter)
app.use('/api/register',registerRouter)


// 管理端接口
app.use('/admin/category',adminAuth,categoryRouter)
app.use('/admin/auth',authRouter)

module.exports = app;
